package com.ushio.gougouwangguo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ushio.gougouwangguo.entity.mysql.MaterialsBattleLog;
import com.ushio.gougouwangguo.mapper.MaterialsBattleLogMapper;
import com.ushio.gougouwangguo.service.MaterialsBattleLogService;
import com.ushio.gougouwangguo.service.MaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class MaterialsBattleLogServiceImpl extends ServiceImpl<MaterialsBattleLogMapper, MaterialsBattleLog> implements MaterialsBattleLogService {


    @Autowired
    MaterialsBattleLogMapper materialsBattleLogMapper;

    public void primaryRewardsForBattleExploration(Long battleLogId){

        Random randomReward = new Random();

        List<MaterialsBattleLog> materialsBattleLogs = new ArrayList<>();

        for (int j = 0; j < 3; j++) {

            int rewardRandomNumber = randomReward.nextInt(100) + 1;

            if (rewardRandomNumber < 33) {

                int quantity = new Random().nextInt(4)+1;

                MaterialsBattleLog materialsBattleLog = MaterialsBattleLog.builder().battleLogId(battleLogId).materialsId(1).quantity(quantity).build();
                materialsBattleLogs.add(materialsBattleLog);
            } else if (rewardRandomNumber<66){

                int quantity = new Random().nextInt(4)+1;

                MaterialsBattleLog materialsBattleLog = MaterialsBattleLog.builder().battleLogId(battleLogId).materialsId(2).quantity(quantity).build();
                materialsBattleLogs.add(materialsBattleLog);
            } else if (rewardRandomNumber>66) {

                int quantity = new Random().nextInt(4)+1;

                MaterialsBattleLog materialsBattleLog = MaterialsBattleLog.builder().battleLogId(battleLogId).materialsId(3).quantity(quantity).build();
                materialsBattleLogs.add(materialsBattleLog);
            }else {
                int quantity = new Random().nextInt(4)+1;

                MaterialsBattleLog materialsBattleLog = MaterialsBattleLog.builder().battleLogId(battleLogId).materialsId(4).quantity(quantity).build();
                materialsBattleLogs.add(materialsBattleLog);
            }
        }
        materialsBattleLogMapper.insert(materialsBattleLogs);
    }



}
